package br.com.NoTraffic.decoder;

import java.io.FileNotFoundException;
import java.io.IOException;

import junit.framework.Assert;

import org.junit.Test;

import br.com.NoTraffic.util.Util;

public class DecoderTester {
	/*
	 * Street="Long Island Expy btwn Queens Midtown Tunnel and Hwy 25 and 58";
	 * RealStatus="Cur speeDl: 55mph | Delay: None";
	 * 
	 * Street=
	 * "New Jersey Turnpike btwn George Washington Bridge and Brick Yard Road";
	 * RealStatus="Cur speed: 63mph | Delay: None";
	 * 
	 * Street=
	 * "Brooklyn Bridge btwn Park Row and Centre Street and Brooklyn Bridge Blvd"
	 * ; RealStatus="Cur speed: 31mph | Delay: None";
	 * 
	 * Street=
	 * "Harlem River Dr btwn US Hwy 1: Cross Bronx Expy and Triborough Bridge";
	 * RealStatus="Cur speed: 38mph | Delay: None";
	 * 
	 * Street="Williamsburg Bridge btwn Clinton Street and Roebling Street";
	 * RealStatus="Cur speed: 44mph | Delay: None";
	 */
	String HTML;

	String Street;
	String Status;
	String RealStatus;

	Decoder decoder;

	public DecoderTester() {
		try {
			HTML = new String(Util.getFileContent("test/HTMLexample.txt"));
		} catch (final FileNotFoundException e) {
			e.printStackTrace();
		} catch (final IOException e) {
			e.printStackTrace();
		}
		decoder = new Decoder(HTML);
	}

	@Test
	public void decodeTest1() {
		Street = "Long Island Expy btwn Queens Midtown Tunnel and Hwy 25 and 58";
		RealStatus = "Sp:55mph Dl:None";
		Status = decoder.getAllInf(Street);

		Assert.assertEquals(RealStatus, Status);

	}

	@Test
	public void decodeTest2() {
		Street = "New Jersey Turnpike btwn George Washington Bridge and Brick Yard Road";
		RealStatus = "Sp:63mph Dl:None";
		Status = decoder.getAllInf(Street);

		Assert.assertEquals(RealStatus, Status);

	}

	@Test
	public void decodeTest3() {
		Street = "Brooklyn Bridge btwn Park Row and Centre Street and Brooklyn Bridge Blvd";
		RealStatus = "Sp:31mph Dl:None";
		Status = decoder.getAllInf(Street);
		Assert.assertEquals(RealStatus, Status);

	}

	@Test
	public void decodeTest4() {
		Street = "Harlem River Dr btwn US Hwy 1: Cross Bronx Expy and Triborough Bridge";
		RealStatus = "Sp:38mph Dl:None";
		Status = decoder.getAllInf(Street);
		Assert.assertEquals(RealStatus, Status);

	}

	@Test
	public void decodeTest5() {
		Street = "Williamsburg Bridge btwn Clinton Street and Roebling Street";
		RealStatus = "Sp:44mph Dl:None";
		Status = decoder.getAllInf(Street);
		Assert.assertEquals(RealStatus, Status);

	}

	@Test
	public void decodeWrongStreet() {
		Street = "Williamsbnton Street and Roebling Street";
		Status = decoder.getAllInf(Street);
		Assert.assertNull(Status);
	}

	@Test
	public void decodeArea1() {
		String[] zone1 = { "Holland Tunnel btwn Marin Blvd and Varick Street",
				"West Side Hwy btwn South Street and W 57th Street",
				"West Shore Expy btwn Staten Island Expy and Korean War Veterans Expy" };
		for (int i = 0; i < 3; i++) {
			Assert.assertNotNull(zone1[i]);
		}
	}

	@Test
	public void decodeArea2() {
		String[] zone2 = {
				"Lincoln Tunnel btwn JFK and Willow Ave and Dyer Ave",
				"I-95 George Washington Bridge btwn Riverside Drive and Hudson Terrace",
				"Manhattan Bridge btwn Bowery and Concord Street" };
		for (int i = 0; i < 3; i++) {
			Assert.assertNotNull(zone2[i]);
		}

	}

	@Test
	public void decodeArea3() {
		String[] zone3 = {
				"Long Island Expy btwn Queens Midtown Tunnel and Hwy 25 and 58",
				"Queens Midtown Tunnel btwn Long Island Expy and 2nd Ave",
				"Brooklyn Bridge btwn Park Row and Centre Street and Brooklyn Bridge Blvd" };
		for (int i = 0; i < 3; i++) {
			Assert.assertNotNull(zone3[i]);
		}

	}

	@Test
	public void decodeArea4() {
		String[] zone4 = {
				"Cross Bronx Expy btwn Riverside Drive and Throgs Neck Expy",
				"Harlem River Dr btwn US Hwy 1: Cross Bronx Expy and Triborough Bridge",
				"Major Deegan Expy btwn Bruckner Blvd and McLean Ave" };
		for (int i = 0; i < 3; i++) {
			Assert.assertNotNull(zone4[i]);
		}
	}
}
